﻿@{
    ViewBag.Title = "My profile";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model RedSand.Site.Models.UserChangeProfile
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.form.js" type="text/javascript"></script>
<script src="/Scripts/rs.ajaxupload.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#choose-image').rsAjaxUpload({
            beforeSubmit: function (arr, form) {
                var filename = $.trim(form.find('input').val());
                var filefilter = ".jpg|.png|.bmp|.gif|.jpeg";
                var ext = filename.substring(filename.lastIndexOf('.')).toLowerCase();
                if (filefilter.indexOf(ext) < 0) {
                    alert("please choose image with extension : jpg, png, bmp, gif, jepg");
                    return false;
                }
                $('#NewAvatar').val(filename);
            },
            success: function (data) {
                if (data.indexOf('Error:') < 0) {
                    data = data.replace('&amp;', '&');
                    $('#imgThumbnai').attr('src', data);
                }
                else {
                    alert(data.replace('Error:', ''));
                }
            },
            error: function (data) {
                alert('file size too large');
                $('#imgThumbnai').attr('src', '');
            }
        });
    })
</script>
<div id="register">
    <h1>
        My Profile
    </h1>
    <div id="error_msg">
    </div>
    @if (User.Identity.IsAuthenticated)
    {
        using (Html.BeginForm("feEditProfile", "Account"))
        {
        <div class="left-register">
            @Html.ValidationSummary(true)
            @Html.HiddenFor(m => m.Avatar)
            <label>
                Username</label>
            <label class="UserName">@Model.Username</label>
            <div class="clr">
            </div>
            @Html.LabelFor(m => m.Fullname)
            @Html.TextBoxFor(m => m.Fullname)
            <div class="clr">
            </div>
            @Html.ValidationMessageFor(m => m.Fullname)
            <label>Password</label>
            <label style="margin-bottom:10px"><a href="/changepassword">Change password</a></label>
            <div class="clr"></div>
            @Html.LabelFor(m => m.Address)
            @Html.TextBoxFor(m => m.Address)
            <div class="clr">
            </div>
            @Html.LabelFor(m => m.Phone)
            @Html.TextBoxFor(m => m.Phone)
            <div class="clr">
            </div>
            @Html.ValidationMessageFor(m => m.Phone)
            @Html.LabelFor(m => m.Email)
            @Html.TextBoxFor(m => m.Email)
            <div class="clr">
            </div>
            @Html.ValidationMessageFor(m => m.Email)
        </div>
        <div id="box-preview">
            <img alt="Preview" id="imgThumbnai" src="@Model.Avatar.GetImageUrl(1)" height="26px" width="26px" />
            <a href="javascript:void(0)" id="choose-image"></a>
            <input type="text" name="NewAvatar" id="NewAvatar" />
        </div>
        <div class="clr">
        </div>
        <input width="63px" type="submit" height="21px" value="Save" class="btn" />
        <div class="clr">
        </div>
        }
    }
</div>
